﻿using AFanDa.BLL.BLLService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AFanDa.Admin.Controllers
{


    [filters.LoginFilter(IsCheck = false)]
    public class LoginController : Controller
    {
        LoginService _loginService = null;

        public LoginController()
        {
            _loginService = new LoginService();
        }


        // GET: Login
        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 验证登录
        /// </summary>
        /// <param name="Account"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public ActionResult Login(string Account, string Password)
        {
            string code = Common.Config.GUID();
            var result = _loginService.Logins(Account, Password, code);

            if (result.code == 0)
            {
                Response.Cookies["code"].Value = code;
            }
            return Json(result);

        }

        /// <summary>
        /// 设置连接id 并返回被踢下线的Id
        /// </summary>
        /// <param name="connectionid"></param>
        /// <returns></returns>
        public ActionResult SetConnection(string connectionid)
        {
            var code = Request.Cookies["code"].Value;

            var resutl = _loginService.SetConnection(code, connectionid);

            return Json(resutl);

        }
    }
}